Skip to content

Tell ptxas the largest block size a kernel can be launched with - #9284

Open
abadams wants to merge 3 commits into
mainfrom
abadams/ptx_block_size_metadata
Open

Tell ptxas the largest block size a kernel can be launched with#9284
abadams wants to merge 3 commits into
mainfrom
abadams/ptx_block_size_metadata

Conversation

@abadams

@abadams abadams commented Aug 5, 2026

Copy link
Copy Markdown
Member

Without it ptxas has to assume a block could hold the maximum number of threads, which caps it at 65536/1024 = 64 registers per thread. The kernel in apps/cuda_mat_mul is launched with 16x2 threads and wants 70 registers, so it spilled: 20 bytes of spill stores and 16 of spill loads. Giving ptxas the bound removes the spills, and the app goes from 0.314 ms to 0.233 ms.

I believe this is the underlying reason we found a benefit in manually messing with the number of registers with an env var - code that was backed out in #9260.

Without it ptxas has to assume a block could hold the maximum number of
threads, which caps it at 65536/1024 = 64 registers per thread. The kernel in
apps/cuda_mat_mul is launched with 16x2 threads and wants 70 registers, so it
spilled: 20 bytes of spill stores and 16 of spill loads. Giving ptxas the bound
removes the spills, and the app goes from 0.314 ms to 0.233 ms.

This has to be a function attribute. The equivalent nvvm.annotations entry,
which is how the kernel annotation just above is written, is upgraded to one of
these when a module is read from a file, but that never happens to a module we
built ourselves, and the backend only looks at the attribute.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

@mcourteaux mcourteaux left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@codecov

codecov Bot commented Aug 6, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 66.66667% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.28%. Comparing base (f932856) to head (0bc8669).

Files with missing lines Patch % Lines
src/CodeGen_PTX_Dev.cpp 66.66% 3 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #9284      +/-   ##
==========================================
- Coverage   70.32%   70.28%   -0.05%     
==========================================
  Files         258      258              
  Lines       79160    79178      +18     
  Branches    18997    19002       +5     
==========================================
- Hits        55672    55652      -20     
+ Misses      17802    17801       -1     
- Partials     5686     5725      +39     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add ability to control PTX max registers and other per entry tuning parameters per Func.

3 participants